//
//  STFeedBackViewController.m
//  STBasicsApp
//
//  Created by jerry on 2019/5/6.
//  Copyright © 2019 jerry. All rights reserved.
//

#import "STFeedBackViewController.h"

@interface STFeedBackViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic , strong) UITableView * tableView;
@property (nonatomic , strong) UIButton    * submitBtn;

@end

@implementation STFeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configNav];
    [self showView];
}

- (void)configNav{
    self.title = ASLocalizedString(@"意见反馈");
}

- (void)showView{
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.bottom.equalTo(self.view.mas_bottom);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
    }];
    
}

#pragma mark - set/get

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
        _tableView.dk_separatorColorPicker = DKColorPickerWithKey(SETTINGSEPARATOR);
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        _tableView.rowHeight = 44;
        _tableView.dk_backgroundColorPicker = DKColorPickerWithKey(SETTINGSEPARATOR);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (UIButton *)submitBtn{
    if (!_submitBtn) {
        CGFloat widht  = 300.0f;
        CGFloat height = 45.0f;
        _submitBtn = [[UIButton alloc]initWithFrame:CGRectMake((OG_SCREEN_WIDTH -widht)/2, 30, widht, height)];
        [_submitBtn setTitle:ASLocalizedString(@"提交") forState:UIControlStateNormal];
        [_submitBtn setBackgroundColor:UIColorFromRGB(0x54DC8E)];
        [_submitBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
        _submitBtn.layer.cornerRadius = height/2.0f;
        _submitBtn.layer.masksToBounds= YES;
        _submitBtn.tag = 1008611;
        [_submitBtn addTarget:self action:@selector(submitAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _submitBtn;
}

#pragma mark - UITableViewDelegate/UITableViewDataSource

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat height = 44.0f;
    return height;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 20;
    }
    return 50;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel * headerView = [[UILabel alloc]init];
    headerView.dk_textColorPicker = DKColorPickerWithKey(NORMALTEXT);
    headerView.dk_backgroundColorPicker = DKColorPickerWithKey(SETTINGSEPARATOR);
    
    if (section == 0) {
        headerView.text = ASLocalizedString(@"");
    }else if (section == 1) {
        headerView.text = ASLocalizedString(@"    请选择反馈问题的类型");
    }else if (section == 2) {
        headerView.text = ASLocalizedString(@"    问题和意见");
    }else if (section == 3) {
        headerView.text = ASLocalizedString(@"    添加图片（选填）");
    }
    
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 3) {
        return 100;
    }
    return 0;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView * footerView = [[UIView alloc]init];
    footerView.backgroundColor = kClearColor;
    [footerView addSubview:self.submitBtn];
    return footerView;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else if (section == 1) {
        return 2;
    }else if (section == 2) {
        return 1;
    }else if (section == 3) {
        return 1;
    }
    return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *ID = @"UITableViewCell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.dk_backgroundColorPicker = DKColorPickerWithKey(TABLECELLBG);
    cell.textLabel.dk_textColorPicker = DKColorPickerWithKey(SETTINGMAINTEXT);
    cell.textLabel.text = @"测试文本";
    
    return cell;
}

#pragma mark - Action

- (void)submitAction:(UIButton *)sender{
    
}

@end
